home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earkit / mail / thor / thor25_arexx.lha / BulkMail.thor < prev    next >
Text File  |  1997-08-25  |  8KB  |  207 lines

  1. /* $VER: BulkMail.thor 2.0 (12.3.97)                    */
  2. /* Searches the User database for Comments or Aliases   */
  3. /* containing the supplied string, and then sends each  */
  4. /* match a copy of the currently selected EMail event.  */
  5. /* V2.0 adds the option to send a single mail to all    */
  6. /* recipients, using either Cc: or Bcc: and a hotlist   */
  7. /* of commonly used search strings                      */
  8.  
  9. options results
  10.  
  11. /* ;;; Set variables */
  12. EVE_ENTERMSG      =  0            /* Event is enter   */
  13. EDF_DELETED       = '00000001'x   /* Event is deleted */
  14. EDF_DONE          = '00000004'x   /* Event is done    */
  15. EDF_FREEZE        = '00000020'x   /* Event is frozen  */
  16. CDF_MAIL          = '00000002'x   /* Mail conference  */
  17. ;;;
  18. /* ;;; Get Thor arexx port and load bbsread.library */
  19. thorport = address()
  20. if left(thorport,5) ~= 'THOR.' then do
  21.     say 'FixMail.thor must be run from within Thor.'
  22.     end
  23.  
  24. if ~show('p', 'BBSREAD') then do
  25.     address command
  26.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  27.     'WaitForPort BBSREAD'
  28.     end
  29. ;;;
  30. /* ;;; Get current system info and selected event number */
  31. address(thorport)
  32. 'CURRENTSYSTEM stem CURRENT'
  33. System = CURRENT.BBSNAME
  34. drop CURRENT.
  35. 'GETSELECTEDEVENT'
  36. if rc = 5 then call ExitMsg('Event window not open')
  37. if rc > 5 then call ExitMsg(THOR.LASTERROR)
  38. EventNo = result
  39. address(bbsread)
  40. drop SYSINFO.
  41. 'GETBBSDATA "'System'" SYSINFO'
  42. DataPath = SYSINFO.BBSPATH
  43. ;;;
  44. /* ;;; Get event details */
  45. address(bbsread)
  46. 'READBREVENT "'System'" eventnr' EventNo 'datastem EVENTDATA tagsstem EVENTTAGS'
  47. if(rc > 0) then call ExitMsg(BBSREAD.LASTERROR)
  48. ;;;
  49. /* ;;; Make sure it is an EMail event and an Enter event */
  50. drop CONFINFO.
  51. 'GETCONFDATA "'System'" "'EVENTTAGS.CONFERENCE'" stem CONFINFO'
  52. if bitand(CONFINFO.FLAGS,CDF_MAIL) ~= CDF_MAIL then call ExitMsg('Selected event is not an EMail event')
  53. if EVENTDATA.EVENTTYPE ~= EVE_ENTERMSG then call ExitMsg('Selected event is not an Enter event')
  54. ;;;
  55. /* ;;; Get string to match on */
  56. address(thorport)
  57. DefaultStr = ''
  58. do while 1 = 1
  59.     'REQUESTSTRING TITLE "Search string" BT "_OK|_Address|_Hotlist|_Cancel" BODY "Enter string to search for\nin User Database" ID "'DefaultStr'"'
  60.     if rc > 5 then call ExitMsg(THOR.LASTERROR)
  61.     MatchString = result
  62.     select
  63.         when THORRC = 1 then leave
  64.         when THORRC = 2 then DefaultStr = EVENTTAGS.TOADDR
  65.         when THORRC = 3 then do
  66.             if ~open(hl,DataPath'BulkMail.hotlist','R') then call ExitMsg('Failed to open hotlist')
  67.             drop LIST.
  68.             n = 0
  69.             do while ~eof(hl)
  70.                 line = readln(hl)
  71.                 if line = '' then leave
  72.                 n = n + 1
  73.                 interpret 'LIST.'n' = line'
  74.                 end
  75.             LIST.COUNT = n
  76.             call close(hl)
  77.             'REQUESTLIST instem LIST outstem tmp title "Select search item"'
  78.             if rc = 5 then exit
  79.             if rc > 0 then call ExitMsg(THOR.LASTERROR)
  80.             DefaultStr = result
  81.             end
  82.         otherwise exit
  83.         end
  84.     end
  85. ;;;
  86. /* ;;; Search User Database for matches */
  87. address(thorport)
  88. 'REQUESTNOTIFY "Search Alias or Comment fields?" "_Alias|_Comment|_Cancel"'
  89. Choice = result
  90. select
  91.     when Choice = 1 then Searchfield = 'ALIAS'
  92.     when Choice = 2 then Searchfield = 'COMMENT'
  93.     otherwise exit
  94.     end
  95.  
  96. address(bbsread)
  97. 'SEARCHBRUSER "'System'" STEM SEARCHRESULT SEARCH "#?'MatchString'#?"' SearchField
  98. if(rc ~= 0) then call ExitMsg(BBSREAD.LASTERROR)
  99. if SearchResult.COUNT = 0 then call ExitMsg('No matches for *"'MatchString'*" found in User database')
  100.  
  101. /* Read names and addresses from user database */
  102. drop Names. Addresses. List.
  103. do i = 1 to SearchResult.COUNT
  104.     UserNo = SearchResult.i.USERNR
  105.     'READBRUSER BBSNAME "'System'" USERNR' UserNo 'TAGSSTEM USERTAGS'
  106.     if rc > 0 then call ExitMsg(BBSREAD.LASTERROR)
  107.     interpret 'Names.'i' = USERTAGS.NAME'
  108.     interpret 'Addresses.'i' = USERTAGS.ADDRESS'
  109.     interpret 'List.'i' = left(USERTAGS.NAME,30)||USERTAGS.ADDRESS'
  110.     end
  111. Names.COUNT     = SearchResult.COUNT
  112. Addresses.COUNT = SearchResult.COUNT
  113. List.COUNT      = SearchResult.COUNT
  114. ;;;
  115. /* ;;; Use all or select? */
  116. address(thorport)
  117. 'REQUESTNOTIFY "'SearchResult.COUNT 'matches found" "_All|_Select|_Cancel"'
  118. if result = 0 then exit
  119. if result = 2 then do           /* Select addresses from list */
  120.     drop Selected.
  121.     'REQUESTLIST instem LIST outstem SELECTED title "Select addresses to send to" MULTISELECT'
  122.     if rc = 5 then exit
  123.     if rc > 0 then call ExitMsg(THOR.LASTERROR)
  124.  
  125.     /* Copy selected entries to Names. and Addresses. stems */
  126.     drop Names. Addresses.
  127.     do i = 1 to Selected.COUNT
  128.         interpret 'Names.'i' = strip(left(Selected.'i',30))'
  129.         interpret 'Addresses.'i' = strip(substr(Selected.'i',31))'
  130.         end
  131.     Names.COUNT = Selected.COUNT
  132.     Addresses.COUNT = Selected.COUNT
  133.     end
  134. ;;;
  135. /* ;;; Create separate or copied messages */
  136. address(thorport)
  137. 'REQUESTNOTIFY "Send a separate email to each recipient?\nOr one mail with all addresses\nincluded in Cc: or Bcc: headers?" "_Separate|_Cc:|_Bcc:|Cancel"'
  138. if rc > 0 then ExitMsg(THOR.LASTERROR)
  139. select
  140.     when result = 0 then exit
  141.     when result = 1 then do                     /* Create separate events for each recipient */
  142.         address(bbsread)
  143.         do i = 1 to Names.COUNT
  144.             interpret 'EVENTTAGS.TONAME = Names.'i
  145.             interpret 'EVENTTAGS.TOADDR = Addresses.'i
  146.             'WRITEBREVENT BBSNAME "'System'" EVENT' EVE_ENTERMSG 'STEM EVENTTAGS'
  147.             if rc > 0 then call ExitMsg(BBSREAD.LASTERROR)
  148.             end
  149.  
  150.         /* Delete original event? */
  151.         address(thorport)
  152.         'REQUESTNOTIFY "'i-1 'Email events created\nDelete original event?" "_Yes|_No"'
  153.         if (result = 1) then do
  154.             address(bbsread)
  155.             'UPDATEBREVENT bbsname "'System'" eventnr' EventNo 'SETDELETED'
  156.             end
  157.         end
  158.     when result = 2 | result = 3 then do        /* Add Cc: or Bcc: headers to original event */
  159.         if result = 2 then hdr = 'Cc: '
  160.         else hdr = 'Bcc: '
  161.         /* Build header string, adding line feed when max length is reached */
  162.         Header = ''
  163.         AddressStr = hdr||Addresses.1
  164.         do i = 2 to Addresses.COUNT
  165.             interpret 'NextAddress = Addresses.'i
  166.             if length(AddressStr','NextAddress) > 250 then do
  167.                 Header = Header||AddressStr||'0a'x
  168.                 AddressStr = hdr
  169.                 end
  170.             else AddressStr = AddressStr','
  171.             AddressStr = AddressStr||NextAddress
  172.             end
  173.         if AddressStr > '' then Header = Header||AddressStr||'0a'x
  174.  
  175.         /* Write headers to message */
  176.         TmpFile = 'T:BulkMail.'time(s)
  177.         if ~open(out,TmpFile,'W') then ExitMsg('Failed to open temporary file' TmpFile)
  178.         if ~open(in,DataPath||EVENTTAGS.MSGFILE) then ExitMsg('Failed to open message file')
  179.         call writech(out,Header)            /* Write cc headers */
  180.         nextline = readln(in)               /* See if message file starts with a custom header */
  181.         firstword = word(nextline,1)        /* otherwise write a blank line */
  182.         if pos(':',firstword) ~= length(firstword) then call writeln(out,'')
  183.         call writeln(out,nextline)
  184.         do until eof(in)
  185.             call writech(out,readch(in,20000))
  186.             end
  187.  
  188.         call close(out)
  189.         call close(in)
  190.         address command
  191.         'delete >NIL:' DataPath||EVENTTAGS.MSGFILE
  192.         'copy >NIL:' TmpFile DataPath||EVENTTAGS.MSGFILE
  193.         'delete >NIL:' TmpFile
  194.         end
  195.     otherwise exit
  196.     end
  197. ;;;
  198. exit
  199.  
  200. /* ;;; Exit with a message */
  201. ExitMsg:
  202.     parse arg ErrTxt
  203.     address(thorport)
  204.     'REQUESTNOTIFY "'ErrTxt'" "Abort"'
  205.     exit
  206. ;;;
  207.